package com.mall.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mall.db.domain.Coupons;
import com.mall.db.service.CouponsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;
import java.util.Map;
@Component
@RequestMapping("/coupons/cs")
public class couponsController extends BaseController<Coupons>{
   @Autowired
    private CouponsService cp;
    @Override
    public Map<String, Object> find(Coupons coupons) {
        QueryWrapper<Coupons> qw = new QueryWrapper<>();
        if (coupons.getName()!=null){
            qw.like("name",coupons.getName());
        }
        List<Coupons> list = cp.list(qw);
        return this.findMap(list,list.size());
    }
    @RequestMapping("/save")
    public Map<String,Object> save(Coupons coupons){
        if (StringUtils.isEmpty(coupons.getId())) {
            boolean b = cp.save(coupons);
            return iud("新增", b, coupons);
        }else {
            boolean b = cp.updateById(coupons);
            return iud("编辑", b, coupons);
        }
    }
    @RequestMapping("/delete")
    public Map<String,Object> delete(Coupons coupons){
        boolean b = cp.removeById(coupons.getId());
        return iud("删除",b,coupons);
    }
}
